﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Sbook.Data
{
    public class NewsGroupController:SqlDataProvider
    {
        #region[NewsGroup_GetByAll]
        public List<NewsGroup> NewsGroup_GetByAll()
        {
            List<Data.NewsGroup> list = new List<Data.NewsGroup>();
            using (SqlCommand dbCmd = new SqlCommand("sp_NewsGroup_GetByAll", GetConnection()))
            {
                Data.NewsGroup obj = new Data.NewsGroup();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.NewsGroupIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion

        #region[NewsGroup_GetByTop]
        public List<NewsGroup> NewsGroup_GetByTop(string Top, string Where, string Order)
        {
            List<Data.NewsGroup> list = new List<Data.NewsGroup>();
            using (SqlCommand dbCmd = new SqlCommand("[sp_NewsGroup_GetByTop]", GetConnection()))
            {
                Data.NewsGroup obj = new Data.NewsGroup();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.NewsGroupIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion

       

        #region[NewsGroup_GetById]
        public List<NewsGroup> NewsGroup_GetById(string Id)
        {
            List<NewsGroup> list = new List<NewsGroup>();
            using (SqlCommand cmd = new SqlCommand("sp_NewsGroup_GetById", GetConnection()))
            {
                Data.NewsGroup obj = new NewsGroup();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@GroupID",Id));
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while(dr.Read())
                    {
                        list.Add(obj.NewsGroupIDataReader(dr));
                    }
                }
            }
            return list;
        }

        #endregion

        #region[NewsGroup_Insert]
        public bool NewsGroup_Insert(NewsGroup group)
        {
            using (SqlCommand cmd = new SqlCommand("sp_NewsGroup_Insert", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@GroupName", group.GroupName));
                cmd.Parameters.Add(new SqlParameter("@gStatus", group.GStatus));
               
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region[NewsGroup_Update]
        public bool NewsGroup_Update(NewsGroup group)
        {
            using (SqlCommand cmd = new SqlCommand("sp_NewsGroup_Update", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@GroupID", group.GroupID));
                cmd.Parameters.Add(new SqlParameter("@GroupName", group.GroupName));
                cmd.Parameters.Add(new SqlParameter("@gStatus", group.GStatus));
                
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region[NewsGroup_UpdateStatusById]
        public bool NewsGroup_UpdateStatusById(string Id, string status)
        {
            using (SqlCommand cmd = new SqlCommand("sp_NewsGroup_UpdateStatusById", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@GroupID", Id));
                cmd.Parameters.Add(new SqlParameter("@gStatus", status));

                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region[NewsGroup_DeleteById]
        public bool NewsGroup_Delete(string Id)
        {
            using (SqlCommand cmd = new SqlCommand("NewsGroup_DeleteById", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@GroupID", Id));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

    }
}